<?php
class AuthenticationAction extends MemberAction{
	public $db;
	public $pagezise=10;
	public $listmap=1;
	public $listorder='id';
	public function _initialize(){
		parent::_initialize();
		$this->db=M('Authentication');
	}
	//会员编辑信息
	public function edit(){
		$this->info = $this->db->where(array('member_id'=>$this->userInfo['id']))->find();
		 
		$this->display();
	}
	//会员更新信息
	public function update(){
		if(isset($_POST)){
			$info = $this->db->where(array('member_id'=>$this->userInfo['id']))->find();
			if(!is_array($info)){
				$_POST['member_id'] = $this->userInfo['id'];
				if(!$this->db->create()){
				    $this->error($this->db->getError());
			    }
				$re = $this->db->add();
			}else{
				if(!$this->db->create()){
				    $this->error($this->db->getError());
			    }
				$re = $this->db->where(array('member_id'=>$this->userInfo['id']))->save();
			}
			
			if(false !== $re){
				$this->success('编辑成功');
			}else{
				$this->error($this->db->getError());
			}
		}else{
			$this->error('没有提交信息');
		}
	}
	public function uploadImg(){
		if(!isset($_FILES['file'])){
			$this->display();exit();
		}else{
		import('ORG.Net.UploadFile');
		$upload = new UploadFile();						// 实例化上传类
		$upload->maxSize = 150*1024;					//设置上传图片的大小
		$upload->allowExts = array('jpg','png','gif');	//设置上传图片的后缀
		$upload->uploadReplace = true;					//同名则替换
		$upload->saveRule = 'uniqid';					//设置上传头像命名规则(临时图片),修改了UploadFile上传类
		//完整的头像路径
		$path = './Public/Uploads/card/'.$this->memberInfo['id'].'/';
		if(!is_dir($path)){
			mkdir($path, 777, true);
		}
		$upload->savePath = $path;
		if(!$upload->upload()) {						// 上传错误提示错误信息
			$this->ajaxReturn('',$upload->getErrorMsg(),0,'json');
		}else{		$this->display();									// 上传成功 获取上传文件信息
			$info =  $upload->getUploadFileInfo();
			$temp_size = getimagesize($path.$info['0']['savename']);
			if($temp_size[0] < 100 || $temp_size[1] < 100){//判断宽和高是否符合头像要求
				$this->ajaxReturn(0,'图片宽或高不得小于100px！',0,'json');
				exit("<script>window.parent.uploaded('0','图片宽或高不得小于100px！');</script>");
			} 
			$data['picName'] = $info['0']['savename'];
			$data['status'] = 1;
			$data['url'] = __ROOT__.'/Public/Uploads/card/'.$this->memberInfo['id'].'/'.$data['picName'];
			$data['info'] = $info;
			
			exit("<script>window.parent.uploaded('1','{$data['url']}');</script>");
		}}
	}
}